package com.kejiguan.ui.request;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.Volley;
import com.android.volley.request.Request;

import java.util.Map;

/**
 * Created by apple on 16/3/31.
 */
public class RequestUtil {

    public static volatile RequestQueue requestQueue;

    public static RequestQueue getRequestQueue(Context context) {
        if (null == requestQueue) {
            synchronized (RequestUtil.class) {
                if (requestQueue == null) {
                    requestQueue = Volley.newRequestQueue(context);
                }
            }
        }

        return requestQueue;
    }

    public static Request sendRequest(Context context, Map<String,String> requestParam, BaseRequest request)
    {
        request.setPostParam(requestParam);
        request.setContext(context.getApplicationContext());
        return getRequestQueue(context).add(request);
    }

    public static Request sendRequest(Context context,Request request)
    {
        request.setContext(context.getApplicationContext());
        return getRequestQueue(context).add(request);
    }
}
